package com.admin.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * @author: wangghua
 * @version: 1.0
 * @date: 2020-11-16 15:46
 **/
@Service
public class EmailService {
    @Value("${spring.mail.username}")
    private String username;

    @Autowired
    JavaMailSender mailSender;

    Logger LOGGER = LoggerFactory.getLogger(this.getClass());


    public void sendSimpleMail(String toEmail, String title, String content) {
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        //设置寄件人
        simpleMailMessage.setFrom(username);
        //设置收件人
        simpleMailMessage.setTo(toEmail);
        //设置标题
        simpleMailMessage.setSubject(title);
        //设置内容
        simpleMailMessage.setText(content);

        //发送邮件
        mailSender.send(simpleMailMessage);

        LOGGER.info("邮件发送成功");
    }
}
